import { store } from "@/store"
import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { showError } from '@/utils/msg-show'
import { getAllApi } from '@/api/sys/national'

export const useNationalStore = defineStore("National", () => {

	const isZero = ref(true)
	const nationalList = ref<any[]>([])
	const nationalListCopy = ref<any[]>([])
	
    /** 获取所有国籍 */
    async function getAll(){
        await getAllApi().then((res: any) => {
            nationalList.value = res.data
            nationalListCopy.value = res.data
		}).catch(err => {
			showError(err.msg || err.errMsg || err)
		})
    }


	/** 初始化 */
	async function init() {
		if (isZero.value) {
            await getAll()
			isZero.value = false
		}
	}

	return {
		init,
        nationalList, nationalListCopy
	}

})

export function useNationalStoreHook() {
	return useNationalStore(store);
}